package com.learn.lb.spark.sql

import java.util.Properties

import org.apache.spark.sql.{Column, SparkSession}

/**
 * 读取jdbc的数据
 *
 * @author laibo
 * @since 2019/8/21 09:44
 *
 */
object ReadJdbcDemo {

  def main(args: Array[String]): Unit = {
    val sparkSession = SparkSession.builder().appName("SparkSessionDemo").master("local[2]").getOrCreate()
    val connProperties = new Properties()
    connProperties.put("user", "root")
    connProperties.put("password", "123456")
    val jdbcDF = sparkSession.read
      .format("jdbc")
      .jdbc("jdbc:mysql://127.0.0.1:3306/eway_helper?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&useSSL=false",
         "sys_log", connProperties)
    jdbcDF.select("id", "username", "operation", "method").show(100, truncate = false)
  }

}
